Skip to main content

How it works

SuperDialog ships a DialogMachineLLM plugin that wires a DialogMachine into a LiveKit Agent via the llm= parameter - the same pattern LiveKit’s own livekit-plugins-langchain uses. LiveKit’s AgentSession drives the conversation (STT → LLM → TTS). DialogMachineLLM sits in the LLM slot and translates between LiveKit’s ChatContext and SuperDialog’s turn() API.

Install

pip install superdialog livekit-agents

Minimal example

from livekit.agents import Agent, AgentSession, JobContext, WorkerOptions, cli
from superdialog import DialogMachine, Flow
from superdialog.adapters.livekit import DialogMachineLLM

dialog_machine = DialogMachine(
    flow=Flow.load("kyc.json"),
    llm="anthropic/claude-opus-4-7",
)

async def entrypoint(ctx: JobContext):
    agent = Agent(llm=DialogMachineLLM(dialog_machine))
    await AgentSession().start(agent=agent, room=ctx.room)

if __name__ == "__main__":
    cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))

With STT and TTS

from livekit.agents import Agent, AgentSession, JobContext, WorkerOptions, cli
from livekit.plugins import deepgram, cartesia
from superdialog import DialogMachine, Flow
from superdialog.adapters.livekit import DialogMachineLLM

dialog_machine = DialogMachine(
    flow=Flow.load("kyc.json"),
    llm="anthropic/claude-haiku-4-5",
)

async def entrypoint(ctx: JobContext):
    await ctx.connect()
    agent = Agent(
        llm=DialogMachineLLM(dialog_machine),
        stt=deepgram.STT(),
        tts=cartesia.TTS(),
    )
    await AgentSession().start(agent=agent, room=ctx.room)

if __name__ == "__main__":
    cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))

Per-call dialog machine

For production, create a fresh DialogMachine per call so conversation state is isolated:
from superdialog import DialogMachine, Flow, PythonTool

flow = Flow.load("kyc.json")   # load once, share by reference

async def entrypoint(ctx: JobContext):
    await ctx.connect()

    # Fresh machine per call
    dm = DialogMachine(
        flow=flow,
        llm="anthropic/claude-haiku-4-5",
        tools=[PythonTool.of(lookup_customer)],
        traversal_dir="./traversal_history",
    )

    agent = Agent(llm=DialogMachineLLM(dm))
    await AgentSession().start(agent=agent, room=ctx.room)

Mid-call context injection

Push system instructions during a call with assist:
# After detecting customer sentiment, inject context
dm.assist("The customer sounds frustrated. Prioritise empathy and resolution speed.")

When to use this adapter

  • You’re already using LiveKit for media routing (rooms, WebRTC, recording)
  • You want SuperDialog to manage turn-by-turn dialog logic
  • You need a clean separation between media transport (LiveKit) and conversation logic (SuperDialog)